package stocks.server;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class JdbcConnect {
	
	private static final String username = "s3198503";
	private static final String password = "jajalol12";
	private static final String url = "jdbc:oracle:thin:@emu.cs.rmit.edu.au:1521:GENERAL";
	private Connection connection;
	private Statement statement;
	private SQLQueries queries;
	
	/**
	 * Constructor for JDBC connection
	 */
	public JdbcConnect()
	{
		try
		{
			Class.forName("oracle.jdbc.driver.OracleDriver"); //oracle class
			connection = DriverManager.getConnection(url,username, password); //connect using user/pass
			statement = connection.createStatement();
		}
		catch(Exception ex)
		{
			System.out.println("Error connecting to database");
			ex.printStackTrace();
			System.exit(1);
		}

	}
	
	/**
	 * Closes database connection, no arguments
	 */
	public void closeConnection()
	{
		try 
		{
			connection.close();
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}
	
	/**
	 * Returns database connection
	 */
	public Connection getConnection()
	{
		return connection;
	}
	
	/**
	 * Returns statement
	 */
	public Statement getStatement()
	{
		return statement;
	}
	
	/**
	 * Returns queries
	 */
	public SQLQueries getQueries()
	{
		return queries;
	}

}
